package object_;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

public class Test2 {
    public static void main(String[] args) {
        String path="D:\\javacode\\javacode\\IO_1\\cat.dat";//读取路径
        ObjectInputStream objectInputStream=null;

        try {
            objectInputStream=new ObjectInputStream(new FileInputStream(path));
            //注意读取顺序需以序列化顺序一致
            System.out.println(objectInputStream.readObject());
            System.out.println(objectInputStream.readInt());
        } catch (IOException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }finally {
            //关闭流
            try {
                if(objectInputStream!=null) {
                    objectInputStream.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
